package cn.imu.service.impl;

import cn.imu.dao.LoginLogMapper;
import cn.imu.dao.UserMapper;
import cn.imu.entity.LoginLog;
import cn.imu.entity.User;
import cn.imu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private LoginLogMapper loginLogMapper;

    @Override
    public boolean hasMatchCount(String user_name, String password) {
       int matchCount= userMapper.getMatchCount(user_name,password);
       return matchCount>0;
    }

    @Override
    public User findUserByUserName(String user_name) {
        return userMapper.findUserByUserName(user_name);
    }

    @Override
    public void loginSuccess(User user) {
       LoginLog loginLog=new LoginLog();
       loginLog.setUser_id(user.getUser_id());
       loginLog.setIp(user.getLast_ip());
       loginLog.setLogin_datetime(user.getLast_visit());
       loginLogMapper.insertLoginLog(loginLog);
    }

    @Override
    public void updateLoginInfo(User user) {

    }

    @Override
    public List<User> getUserList() {
        return null;
    }

    @Override
    public int addUser(User user) {
        int num= userMapper.addUser(user);
        return num;
    }
}
